﻿#include "AddInventoryDialog.h"
#include <QFont>
#include <QHBoxLayout>
#include <QDate>

AddInventoryDialog::AddInventoryDialog(QWidget *parent)
    : QDialog(parent),
      mainLayout(new QVBoxLayout(this)),
      kindComboBox(new QComboBox(this)),
      quantityInput(new QLineEdit(this)),
      priceInput(new QLineEdit(this)),  // Initialize price input
      dateEdit(new QDateEdit(QDate::currentDate(), this)),  // Initialize date edit with current date
      okButton(new QPushButton("确认添加", this)),
      cancelButton(new QPushButton("取消", this)) {

    setStyleSheet(
        "QLineEdit, QDateEdit {"
        "  font-size: 18px;"
        "  font-weight: bold;"
        "  border: 2px solid #E0E0E0;"
        "  border-radius: 20px;"
        "  padding: 10px;"
        "  color: gray;"
        "}"
        "QComboBox {"
        "  font-size: 18px;"
        "  font-weight: bold;"
        "  border: 2px solid #E0E0E0;"
        "  border-radius: 20px;"
        "  padding: 10px;"
        "  color: gray;"
        "}"
        "QPushButton {"
        "  font-size: 18px;"
        "  font-weight: bold;"
        "  border: 2px solid #E0E0E0;"
        "  border-radius: 20px;"
        "  padding: 10px;"
        "  background-color: #0093D1;"
        "  color: white;"
        "}"
    );

    setWindowTitle("原料信息");

    // Populate the kindComboBox with "A-Z" options
    for (char c = 'A'; c <= 'Z'; ++c) {
        kindComboBox->addItem(QString(c));
    }

    // Setup the layout
    QFont font;
    font.setPointSize(14); // Adjust the font size as needed

    QLabel *kindLabel = new QLabel("种类:", this);
    kindLabel->setFont(font);
    kindComboBox->setFont(font);
    kindComboBox->setMinimumHeight(40);

    QLabel *quantityLabel = new QLabel("采购数量:", this);  // Updated label text
    quantityLabel->setFont(font);
    quantityInput->setFont(font);
    quantityInput->setMinimumHeight(40);

    QLabel *priceLabel = new QLabel("单价:", this);  // Added price label
    priceLabel->setFont(font);
    priceInput->setFont(font);
    priceInput->setMinimumHeight(40);

    QLabel *dateLabel = new QLabel("入库日期:", this);  // Added date label
    dateLabel->setFont(font);
    dateEdit->setFont(font);
    dateEdit->setMinimumHeight(40);
    dateEdit->setCalendarPopup(true);  // Enable calendar popup

    okButton->setFont(font);
    okButton->setMinimumHeight(40);

    cancelButton->setFont(font);
    cancelButton->setMinimumHeight(40);

    mainLayout->addWidget(kindLabel);
    mainLayout->addWidget(kindComboBox);
    mainLayout->addWidget(quantityLabel);
    mainLayout->addWidget(quantityInput);
    mainLayout->addWidget(priceLabel);
    mainLayout->addWidget(priceInput);
    mainLayout->addWidget(dateLabel);
    mainLayout->addWidget(dateEdit);

    QHBoxLayout *buttonLayout = new QHBoxLayout;
    buttonLayout->addWidget(okButton);
    buttonLayout->addWidget(cancelButton);

    mainLayout->addLayout(buttonLayout);

    // Connect buttons to their respective slots
    connect(okButton, &QPushButton::clicked, this, &QDialog::accept);
    connect(cancelButton, &QPushButton::clicked, this, &QDialog::reject);

    // Adjust the dialog size
    setMinimumSize(400, 400);
 // Adjust the size as needed
}

AddInventoryDialog::~AddInventoryDialog() {
    // No need to delete child widgets, Qt does it automatically
}
